

"""无重复字符的最长子串"""
from collections import Counter


class Solution:

    # 滑动窗口
    def lengthOfLongestSubstring(self, s: str) -> int:
        left = 0
        right = 0
        window = Counter()
        res = 0

        while right < len(s):
            # 扩大窗口
            c = s[right]
            right += 1
            # 更新窗口内的数据
            window[c] += 1

            while window[c] > 1:
                # 减小窗口
                d = s[left]
                left += 1
                # 更新窗口内的数据
                window[d] -= 1
            # 更新结果
            res = max(res, right - left)

        return res


if __name__ == '__main__':
    sl = Solution()
    print(sl.lengthOfLongestSubstring('abcabcbb'))